package com.kb5173.search.common.define.enums;

import org.apache.commons.lang.StringUtils;

/**
 * 服务响应码
 * @author Chengfei.Sun
 */
public enum ResponseCodes {
    SUCCESS("00", "操作成功"),

    EmptyKeyWords("1001", "搜索关键字不能为空"),
    EmptyOptionType("1002", "索引操作类型不能为空"),
    EmptyType("1003", "物品类型不能为空"),
    EmptySource("1004", "来源不能为空"),
    EmptyGameName("1005", "游戏名称不能为空"),
    EmptyGameArea("1006", "游戏区不能为空"),
    EmptyGameServer("1007", "游戏服不能为空"),
    EmptyTitle("1008", "标题不能为空"),
    EmptyOfferno("1009", "商品编号不能为空"),
    EmptySellerId("1010", "卖家Id不能为空"),
    EmptyUnitPrice("1011", "商品单价不能为空"),
    EmptyQuantity("1012", "商品数量不能为空"),
    EmptyExpireDate("1013", "过期日期不能为空"),
    EmptyUnitName("1014", "物品名称不能为空"),
    EmptyWords("1015", "自定义分词不能为空"),
    EmptyIndexId("1016", "索引ID不能为空");

    /**
     * 返回码
     */
    private String code;

    /**
     * 返回码说明
     */
    private String message;

    ResponseCodes(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 通过code获取对应的ResponseCodes
     * @param code 错误码
     * @return 响应码对应的ResponseCodes枚举
     */
    public static ResponseCodes getResponseByCode(String code){
        if(StringUtils.isEmpty(code)){
            throw new NullPointerException("响应编码为空");
        }

        for(ResponseCodes responseCode : ResponseCodes.values()){
            if(responseCode.getCode().equals(code)){
                return responseCode;
            }
        }

        throw new IllegalArgumentException("未能找到匹配的ResponseCodes:" + code);
    }

    /**
     * 获取响应编码
     * @return
     */
    public String getCode(){
        return this.code;
    }

    /**
     * 获取响应信息
     * @return
     */
    public String getMessage(){
        return this.message;
    }
}
